home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / cameraChar.lua < prev    next >
Text File  |  2004-01-29  |  9KB  |  331 lines

  1. -- camera character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.         local camera = getStateObjectFromID(msg.sender);
  6.         storeStateObject("camera", camera);
  7.         
  8.         if (camera) then
  9. --            -- camera does exist
  10. --            if (getParent().isOneActionPointLocked(camera)) then
  11. --                -- action point is locked
  12. --                getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  13. --                sendMsg("emoThink", getParent().walkSO);
  14. --                exitStateMachine();
  15. --            else
  16. --                getParent().lockActionPoints(camera);
  17. --            end
  18.         else
  19.             -- camera does not exist anymore
  20.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  21.             sendMsg("emoThink", getParent().walkSO);
  22.             exitStateMachine();
  23.         end
  24.         
  25.         freeHands(getParent());
  26.                 
  27.     end )
  28.     
  29.     onExit(function(msg)
  30. --        local camera = retrieveStateObject("camera");
  31. --        if (camera) then
  32. --            getParent().unlockActionPoints(camera);
  33. --            getParent().stopAllActivities(camera);
  34. --            removeStateObject("camera");
  35. --        end
  36.  
  37.         print("----- cameraChar onExit 1 " .. getParent().getCharacterName());            
  38.         unlockAll("camera");
  39.         print("----- cameraChar onExit 2 " .. getParent().getCharacterName());            
  40.         local partner = retrieveStateObject("partner");
  41.         if (partner) then
  42.             getParent().unlockActionPoints(partner.getParent());
  43.             getParent().stopAllActivities(partner.getParent());
  44.             removeStateObject("partner");
  45.         end;
  46.         
  47.     end )
  48.     
  49. --    state("waitForPartner")
  50. --    
  51. --        onEnter(function(msg)
  52. --            sendDelayedMsgThis("stopWaiting", 20000);
  53. --            this.actionComplete();
  54. --        end )
  55. --        
  56. --        onMsg("stopWaiting", function(msg)
  57. --            local camera = retrieveStateObject("camera");
  58. --            getParent().stopActivity("takePicture", camera);
  59. --            exitStateMachine();
  60. --        end )            
  61. --        
  62. --        onMsg("partnerReady", function(msg)
  63. --            setState("takePicture");
  64. --        end )    
  65. --
  66. --
  67. --        onMsg("queue", function(msg)
  68. --            sendMsgThis("stopWaiting");
  69. --        end )
  70.         
  71.  
  72.         
  73.             
  74.         
  75.         
  76.     state("waitForPartner")
  77.     
  78.         onEnter(function(msg)
  79.         
  80.             local camera = getStateObjectFromID(msg.sender);
  81.             if (getParent().isActionPointLocked(camera, "use")) then
  82.                 -- action point is locked
  83.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  84.                 sendMsg("emoThink", getParent().walkSO);
  85.                 exitStateMachine();
  86.             else
  87.                 getParent().lockActionPoint(camera, "use");
  88.             end
  89.         
  90.             setPose(archize(getParent(),"stand1"));
  91.         
  92.             print("waitForPartner onEnter");
  93.                         
  94.             sendDelayedMsgThis("callPartner", 1000);
  95.             sendDelayedMsgThis("stopWaiting", 20000);
  96.             this.actionComplete();
  97.             
  98.             startAnimation("emoSwingArms");
  99.         end )
  100.         
  101.         onMsg("end", function(msg)
  102.             startAnimation("emoSwingArms");
  103.         end )
  104.         
  105.         onMsg("queue", function(msg)
  106.             sendMsgThis("stopWaiting");
  107.         end )
  108.         
  109.         onMsg("stopWaiting", function(msg)
  110.             exitStateMachine();
  111.         end )
  112.                 
  113.         onMsg("callPartner", function(msg)
  114.         
  115.             print("callPartner");
  116.             
  117.             if testCancel() then
  118.                 sendMsgThis("stopWaiting");
  119.                 return
  120.             end            
  121.             
  122.             -- get the game object server
  123.             local gameObjectServer = getParent().getGameObjectServer();
  124.                     
  125.             
  126.             local partner = getOtherCharacter(getParent());
  127.             
  128.             if (not partner) then
  129.                 print("waitForPartner: no partner found");
  130.                 getParent().setEmoticon(EMOTICON_PARTNER, EMOTICON_DELAY);
  131.                 sendDelayedMsgThis("callPartner", 1000);
  132.                 return
  133.             end
  134.             
  135.             local camera = retrieveStateObject("camera");
  136.             
  137.             local poseActionPointsInSight = getActionPointsInSight(camera, "center", 1.7, camera, {"pose1","pose2","pose3"}, 1.7, partner);
  138. --            local poseActionPoint = partner.getClosestFreeActionPoint(partner, camera, tremoven(poseActionPointsInSight));
  139.             local poseActionPoint = partner.getClosestFreeActionPoint(partner, camera, tremoven(poseActionPointsInSight), true);
  140.             if (not poseActionPoint) then
  141.                 print("waitForPartner: poseActionPoint not found");
  142.                 partner.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  143.                 sendDelayedMsgThis("callPartner", 1000);
  144.                 return
  145.             end
  146.             
  147. --            local wso = partner.walkSO;
  148. --            wso.storeData("actionPointName", poseActionPoint.getName());
  149. --            
  150. --            if (not wso.walkToActionPoint(poseActionPoint)) then
  151. --                print("waitForPartner: partner cant reach poseActionPoint");
  152. --                partner.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  153. --                sendDelayedMsgThis("callPartner", 1000);
  154. --                return
  155. --            end
  156. --            
  157. --            storeStateObject("partner", wso);
  158. --            
  159. --            -- create partners state machine contexts
  160. --            local wsoContext = StateMachineContext();
  161. --            wsoContext.storeStateObject("camera", camera);
  162. --            wsoContext.storeStateObject("partner", this);
  163. --            wsoContext.storeData("poseActionPoint", poseActionPoint.getName());
  164. --
  165. --            -- send partner to chair
  166. --            wso.queueStateMachine("cameraChar.pose", camera, wsoContext);
  167.  
  168.             storeStateObject("partner", partner.walkSO);
  169.  
  170.             local wsoContext = StateMachineContext();
  171.             wsoContext.storeStateObject("camera", camera);
  172.             wsoContext.storeStateObject("partner", this);
  173.             wsoContext.storeData("actionPointName", poseActionPoint.getName());
  174.  
  175.             -- queue walk and state change msg for this(passive) character
  176.             local passiveMsg = QueuedMessage();
  177.             passiveMsg.set(Message.MSG_RESERVED_EnterStateMachine, camera.getUniqueID(), "cameraChar.poseWait", wsoContext);
  178.             partner.pushWalkActionPoint("pm_pose", poseActionPoint, false, passiveMsg);
  179.         
  180.         
  181.         
  182.         end )
  183.                         
  184.         onMsg("partnerReady", function(msg)
  185.             print("----- partner of " .. getParent().getCharacterName() .. " is ready -----");            
  186.             local partner = retrieveStateObject("partner");
  187.             setState("takePicture");
  188.             sendMsg("partnerReady", partner);
  189.         end )
  190.             
  191.     
  192.     state("takePicture")
  193.     
  194.         onEnter(function(msg)
  195.             local camera = retrieveStateObject("camera");
  196.             getParent().startActivity("takePicture", camera);
  197.             startAnimation("takePictureStart");
  198.             sendDelayedMsgThis("clickSound", 900);
  199.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  200.         end )
  201.     
  202.         onMsg("clickSound", function(msg)
  203.             getParent().playSound("cameraShots");
  204.         end )
  205.             
  206.         onMsg("stopTakePicture", function(msg)
  207.             setState("takePictureStop");
  208.         end )    
  209.         
  210.         onMsg("testCancel", function(msg)
  211.             if testCancel() then
  212.                 local partner = retrieveStateObject("partner");
  213.                 sendMsg("stopPose", partner);
  214.                 sendMsgThis("stopTakePicture");
  215.             else
  216.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  217.             end
  218.         end )
  219.  
  220.         onMsg("end", function(msg)
  221.             sendDelayedMsgThis("stopTakePicture", 11000);
  222.         end )
  223.             
  224.     state("takePictureStop")
  225.     
  226.         onEnter(function(msg)
  227.             startAnimation("takePictureStop");
  228.         end )
  229.     
  230.  
  231.         onMsg("end", function(msg)
  232.             local camera = retrieveStateObject("camera");
  233.             getParent().stopActivity("takePicture", camera);
  234.             exitStateMachine();
  235.         end )
  236.         
  237.         
  238.     state("poseWait")
  239.     
  240.         onEnter(function(msg)
  241.             print("--poseWait onEnter--- " .. getParent().getCharacterName());
  242.             local camera = retrieveStateObject("camera");
  243.             local actionPointName = retrieveData("actionPointName");
  244.             
  245.             if (getParent().isActionPointLocked(camera, actionPointName)) then
  246.                 -- action point is locked
  247.                 sendMsgThis("stop");
  248.                 return
  249.             else
  250.                 getParent().lockActionPoint(camera, actionPointName);
  251.             end
  252.                         
  253.             local partner = retrieveStateObject("partner");
  254.             sendDelayedMsgThis("ready", 1000);
  255.             sendDelayedMsgThis("stop", 5000);
  256.             
  257.             startAnimation("emoSwingArms");
  258.         end )
  259.         
  260.         onMsg("end", function(msg)
  261.             startAnimation("emoSwingArms");
  262.         end )
  263.         
  264.         onMsg("stop", function(msg)
  265.             print("----- " .. getParent().getCharacterName() .. " has stopped waiting ----- ");
  266.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  267.             sendMsg("emoThink", getParent().walkSO);
  268.             exitStateMachine();
  269.         end )    
  270.         
  271.         onMsg("ready", function(msg)
  272.             print("----- " .. getParent().getCharacterName() .. " is ready ----- cancel: ");
  273.             -- send a message to the partner
  274.             
  275.             local partner = retrieveStateObject("partner");            
  276.             if (testCancel()) then
  277.                 sendMsgThis("stop");
  278.             else                        
  279.                 sendMsg("partnerReady", partner);
  280.                 sendDelayedMsgThis("ready", 1000);
  281.             end
  282.         end )
  283.         
  284.         onMsg("partnerReady", function(msg)
  285.             print("----- partner of " .. getParent().getCharacterName() .. " is ready -----");
  286.             
  287.             local partner = retrieveStateObject("partner");
  288.             setState("pose");
  289.             sendMsg("partnerReady", partner);
  290.         end )
  291.                     
  292.         
  293.         
  294.     state("pose")
  295.     
  296.         onEnter(function(msg)
  297.             print("----- pose onEnter " .. getParent().getCharacterName());
  298.             local camera = retrieveStateObject("camera");
  299.             getParent().startActivity("pose", camera);
  300.             startAnimation("emoFlirt");
  301.                 
  302.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  303.         end )
  304.         
  305.         
  306.         onMsg("testCancel", function(msg)
  307.             if testCancel() then
  308.                 local partner = retrieveStateObject("partner");
  309.                 sendMsg("stopTakePicture", partner);
  310.                 sendMsgThis("stopPose");
  311.             else
  312.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  313.             end
  314.         end )
  315.         
  316.     
  317.         onMsg("stopPose", function(msg)
  318.             local camera = retrieveStateObject("camera");
  319.             getParent().stopActivity("pose", camera);
  320.             exitStateMachine();
  321.         end )    
  322.  
  323.         onMsg("end", function(msg)
  324.             sendMsgThis("stopPose");
  325.         end )    
  326.         
  327.         
  328.  
  329.                 
  330. endStateMachine()
  331.